@function first($list) {
    @return nth($list, 1);
}

@function last($list) {
    @return nth($list, length($list));
}

@function double($font-size, $line-height, $original-height: $line-height, $counter: 0) {

    @if $font-size > $line-height {
        @return double($font-size, $line-height + $original-height, $original-height, $counter + 1)
    }

    @return $counter;

}

@function is-nested-selector($parent, $child) {

    @if $parent == $child {
        @return false;
    }

    @if length($child) <= 1 {
        @return false;
    }

    @each $rule in $parent {

        $index: index($parent, $rule);

        @if nth($child, $index) != $rule {
            @return false
        }

    }

    @return true;
}

@function _length($number, $unit) {
    $strings: 'px' '%' 'em' 'rem' 'vw' 'vh';
    $units: 1px 1% 1em 1rem 1vw 1vh;
    $index: index($strings, $unit);

    @if not $index {
        @warn "Unknown unit `#{$unit}`.";
        @return false;
    }

    @return $number * nth($units, $index);
}

@function number($value) {

    @if type-of($value) == 'number' {
        @return $value;
    }

    $result: 0;
    $digits: 0;
    $minus: str-slice($value, 1, 1) == '-';
    $numbers: ('0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9);

    @for $i from if($minus, 2, 1) through str-length($value) {
        $character: str-slice($value, $i, $i);

        @if not (index(map-keys($numbers), $character) or $character == '.') {
            @return _length(if($minus, -$result, $result), str-slice($value, $i))
        }

        @if $character == '.' {
            $digits: 1;
        } @else if $digits == 0 {
            $result: $result * 10 + map-get($numbers, $character);
        } @else {
            $digits: $digits * 10;
            $result: $result + map-get($numbers, $character) / $digits;
        }
    }

    @return if($minus, -$result, $result);

}

@function clear-units($number) {
    @return $number / ($number * 0 + 1);
}
